package logic

import (
	"context"
	"doctor-medicine-system/moder/mysql"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedicineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineLogic {
	return &MedicineLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MedicineLogic) Medicine(in *doctorrpc.MedicineRequest) (*doctorrpc.MedicineResponse, error) {
	// todo: add your logic here and delete this line
	medicine := mysql.Medicine{
		Name:     in.Name,
		Num:      in.Num,
		Quantity: int(in.Quantity),
		Price:    int(in.Price),
		UserId:   int(in.UserId),
	}
	err := medicine.MedicineAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &doctorrpc.MedicineResponse{
		MedicineId: int64(medicine.ID),
	}, nil
}
